$(document).ready(function() {
	// 修改员工操作
		$("#developer input:nth-child(odd)").click(function() {
			var developerTr = $(this).parent().parent();
			var devloperId = $.trim(developerTr.attr("did"));
			$("#depId").val(devloperId);
			var tds = $("td", developerTr);
			var developerNum = $.trim(tds.eq(1).html());
			$("#developerNum").val(developerNum);
			var developerName = $.trim(tds.eq(2).html());
			$("#developerName").val(developerName);
			var sex = $.trim(tds.eq(3).html());
			$("#sex").val(sex);
			var cellPhone = $.trim(tds.eq(4).html());
			$("#cellPhone").val(cellPhone);
			if (devloperId != 0) {
				$("#developerUpdate").css( {
					background : "blue"
				});
				$("#developerAdd").css("display", "none");
			}
			$.blockUI( {
				message : $('#stencil'),
				css : {
					width : '380px',
					border : '3px solid #a00'
				}
			});
		});

		// 点击确定按钮所做的事
		$("#yes").click(function() {
			var depId = $("#depId").val();
			var developerNum = $("#developerNum").val();
			var developerName = $("#developerName").val();
			var sex = $("#sex").val();
			var cellPhone = $("#cellPhone").val();
			if (depId != 0) {
				// 修改
				$.ajax( {
					type : "POST",
					cache : false,
					url : "developerManage!updateDeveloper",
					data : "depId=" + depId + "&developerNum="
							+ encodeURI(encodeURI(developerNum))
							+ "&developerName="
							+ encodeURI(encodeURI(developerName)) + "&sex="
							+ encodeURI(encodeURI(sex)) + "&cellPhone="
							+ encodeURI(encodeURI(cellPhone)),
					success : function(message) {
						alert("successfully!");
						var developerTr = $("tr[did=" + depId + "]");
						var tds = $("td", developerTr);
						tds.eq(1).html(developerNum);
						tds.eq(2).html(developerName);
						tds.eq(3).html(sex);
						tds.eq(4).html(cellPhone);
						$.unblockUI();
					}
				});
			} else {
				// 添加
				$.ajax( {
					type : "POST",
					cahce : false,
					url : "developerManage!saveDeveloper",
					data : "developerNum=" + encodeURI(encodeURI(developerNum))
							+ "&developerName="
							+ encodeURI(encodeURI(developerName)) + "&sex="
							+ encodeURI(encodeURI(sex)) + "&cellPhone="
							+ encodeURI(encodeURI(cellPhone)),
					success : function(message) {
						alert("添加开发人员成功！");
						$.unblockUI();
						window.location = "APageTest.jsp";
					},
					error : function(error) {
						alert(error.statusText);
					}
				});
			}
		});

		// 点击取消按钮所做的事
		$("#no").click(function() {
			$("#developerNum").val("");
			$("#developerName").val("");
			$("#sex").val("");
			$("#cellPhone").val("");
			$.unblockUI();
		});

		// 删除员工操作
		$("#developer input:nth-child(even)").click(function() {
			var developerTr = $(this).parents("tr");
			var depId = $.trim(developerTr.attr("did"));
			if (confirm("你确定删除此员工吗?")) {
				$.ajax( {
					url : "developerManage!deleteDeveloper",
					data : "depId=" + depId
				});
				// 刷新页面
				window.location = "APageTest.jsp";
			}
		});

		// 添加员工操作
		$("#btnAddDeveloper").click(function() {
			var depId = $("#depId").val();
			if (depId == 0) {
				$("#developerAdd").css( {
					background : "blue"
				});
				$("#developerUpdate").css("display", "none");
			}
			$("#depId").val(0);
			$.blockUI( {
				message : $('#stencil'),
				css : {
					width : '500px',
					border : '3px solid #a00'
				}
			});
		});

		// 验证
		$("#developerNum").change(function() {
			var developerNum = $("#developerNum").val();
			$.ajax( {
				url : "developerManage!validateDeveloperNum",
				data : "developerNum=" + developerNum,
				cahce : false,
				success : function(message) {
					$(".developerNum").html(message);
				}
			});
		});
	});